package ynu.edu.controller;


import org.springframework.web.bind.annotation.*;
import ynu.edu.entity.User;

@RestController
@RequestMapping("/user")
public class UserController {
    // 原有的GET方法
    @GetMapping("/getUserById/{userId}")
    public User GetUserById(@PathVariable("userId") Integer userId){
        User user = new User();
        user.setUserId(userId);
        user.setUserName("小明 from 11001");
        user.setPassWord("123456");
        return user;
    }

    // 新增POST方法 - 创建用户
    @PostMapping("/create")
    public User createUser(@RequestBody User newUser) {
        return newUser;
    }

    // 新增PUT方法 - 更新用户信息
    @PutMapping("/update/{userId}")
    public User updateUser(@PathVariable Integer userId, @RequestBody User updatedUser) {
        updatedUser.setUserId(userId); // 确保ID一致
        return updatedUser;
    }

    // 新增DELETE方法 - 删除用户
    @DeleteMapping("/delete/{userId}")
    public String deleteUser(@PathVariable Integer userId) {
        return "用户ID为" + userId + "的用户已删除";
    }
}